package cn.senjoeson.triper.fragment;

import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.v4.app.Fragment;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;

import java.util.List;

import butterknife.BindView;
import butterknife.ButterKnife;
import butterknife.Unbinder;
import cn.senjoeson.triper.R;
import cn.senjoeson.triper.adapter.DinningListAdapter;
import cn.senjoeson.triper.base.GreenDaoManager;
import cn.senjoeson.triper.bean.FoodDrinkBean;
import cn.senjoeson.triper.dao.FoodDrinkBeanDao;

/**
 * Created by senjoeson on 2018/2/10.
 */
public class SearchListFragment extends Fragment {
    @BindView(R.id.recyclerview)
    RecyclerView mRecyclerview;
    Unbinder unbinder;

    @Nullable
    @Override
    public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
        View view = inflater.inflate(R.layout.serarch_list_item, container, false);
        unbinder = ButterKnife.bind(this, view);
        initView();
        return view;
    }

    private void initView() {
        Bundle arguments = getArguments();
        String content = arguments.getString("content");
        FoodDrinkBeanDao foodDrinkBeanDao = GreenDaoManager.getInstance().getNewSession().getFoodDrinkBeanDao();
        List<FoodDrinkBean> list = foodDrinkBeanDao.queryBuilder().where(FoodDrinkBeanDao.Properties.DinningName.like("%"+content+"%")).build().list();
        if(list!=null){

            mRecyclerview.setLayoutManager(new LinearLayoutManager(getContext()));
            DinningListAdapter placeListAdapter = new DinningListAdapter(getContext());
            placeListAdapter.setDatas(list);
            mRecyclerview.setAdapter(placeListAdapter);
        }
    }

    @Override
    public void onDestroyView() {
        super.onDestroyView();
        unbinder.unbind();
    }
}
